Square = function(img)
{
	this.image = img;

	
	this.draw=function(x, y,  g)
	{
		if( this.image != null)
		{
			g.drawImage(this.image,x,y);
		}
	}
}

SquareGroup = function(img,typ)
{	typ = typ || 0;
	var bias=	[ 
	  			[ [0,1],[1,1],[2,1],[3,1] ],//0
				[ [1,0],[1,1],[1,2],[1,3] ],//1
				[ [0,0],[1,0],[0,1],[1,1] ],//2
				[ [0,0],[0,1],[1,1],[1,2] ],//3
				[ [1,0],[2,0],[0,1],[1,1] ],//4
				[ [1,0],[0,1],[1,1],[0,2] ],//5
				[ [0,0],[1,0],[1,1],[2,1] ],//6
				[ [0,0],[0,1],[0,2],[1,2] ],//7
				[ [0,0],[1,0],[2,0],[0,1] ],//8
				[ [0,0],[1,0],[1,1],[1,2] ],//9
				[ [2,0],[0,1],[1,1],[2,1] ],//10
				[ [1,0],[0,1],[1,1],[2,1] ],//11
				[ [0,0],[0,1],[1,1],[0,2] ],//12
				[ [0,0],[1,0],[2,0],[1,1] ],//13
				[ [1,0],[0,1],[1,1],[1,2] ],//14
				[ [0,0],[0,1],[1,1],[2,1] ],//15
				[ [0,0],[1,0],[0,1],[0,2] ],//16
				[ [0,0],[1,0],[2,0],[2,1] ],//17
				[ [1,0],[1,1],[0,2],[1,2] ]
				];//18

	var rotateType =[1,0,2,4,3,6,5,8,9,10,7,12,13,14,11,16,17,18,15];
	var type = typ;
	this.square = new Square(img);
	var squareWidth,squareHeight;
	squareWidth = squareHeight = 27 ;


	this.rotate = function()
	{
		type = rotateType[ type ];//System.out.println("OUT GROUP rotate");
	}

	this.getRotateBias = function()
	{
		return bias[ rotateType[ type ] ];
	}

	this.getBias = function()
	{
		return bias[ type ];
	}

	this.getType = function()
	{
		return type;
	}

	this.draw = function( x, y,g)
	{
		for( var i=0; i< 4 ; i++)
		{
			this.square.draw( x+ bias[type][i][0]*squareWidth, y+ bias[type][i][1]*squareHeight,g);
		}
	}
}
SquareGroup.TYPE_NUMS = 19;